package com.atguigu.gmall.user.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.AuthContextHolder;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.user.service.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author atguigu-mqx
 * @Description TODO
 * @Date 2023/7/22 14:15
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/user/userAddress")
public class UserApiController {

    @Autowired
    private UserAddressService userAddressService;

    /**
     * 获取收货地址列表.
     * @param request
     * @return
     */
    @GetMapping("/auth/findUserAddressList")
    public Result findUserAddressList(HttpServletRequest request){
        //  获取用户Id
        String userId = AuthContextHolder.getUserId(request);
        //  调用服务层方法.
        List<UserAddress> userAddressList = userAddressService.findUserAddressList(userId);
        return Result.ok(userAddressList);
    }

}
